package com.objectproject.main.dao;


import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.objectproject.main.dao.iface.MyObjectDAO;
import com.objectproject.main.dao.mybatis.mapper.MyObjectMapper;
import com.objectproject.main.model.MyObject;
import com.objectproject.main.service.subsystem.MyLocaleResolver;

@Repository
public class MyObjectDAOImpl implements MyObjectDAO {
	
	private static final Logger logger = LoggerFactory.getLogger(MyObjectDAOImpl.class);
	
	@Autowired
	MyPropertyDAOImpl myPropertyDAOImpl;
	
	@Autowired
	MyLocaleResolver myLocaleResolver;
	
	@Autowired
	SqlSession sqlSession;

	@Override
	public MyObject selectMyObjectById(long objectId) {
		
		logger.info("Method invocation : selectMyObjectById(" + objectId + ")");
		
		MyObject myObject =  sqlSession.getMapper(MyObjectMapper.class).selectMyObjectById(objectId);
		
		return myObject;

	}

	//@Transactional(propagation=Propagation.REQUIRED)
	public long insertMyObject(MyObject myObject) {
		
		logger.info("Method invocation : insertMyObject");
		
		sqlSession.getMapper(MyObjectMapper.class).insertMyObject(myObject);
		
		return myObject.getObjectId();

	}
	
	//@Transactional(propagation=Propagation.REQUIRED)
		public long insertMyObjectLocaleSpecific(MyObject myObject) {
			
			logger.info("Method invocation : insertMyObject");
			
			sqlSession.getMapper(MyObjectMapper.class).insertMyObjectLocaleSpecific(myObject);
			
			return myObject.getObjectId();

		}

	@Override
	public void protectedDeleteMyObject(MyObject myObject) {
		logger.info("Method invocation : deleteMyObject");
			
		sqlSession.getMapper(MyObjectMapper.class).protectedDeleteMyObject(myObject);
	}
		
	@Override
	public void deleteMyObject(MyObject myObject) {
		logger.info("Method invocation : deleteMyObject");
		
		sqlSession.getMapper(MyObjectMapper.class).deleteMyObject(myObject);
	}

	@Override
	public void protectedDeleteMyObjectById(long objectId) {
		logger.info("Method invocation : deleteMyObjectById");
		
		sqlSession.getMapper(MyObjectMapper.class).protectedDeleteMyObjectById(objectId);
	}
	
	@Override
	public void deleteMyObjectById(long objectId) {
		logger.info("Method invocation : deleteMyObjectById");
		
		sqlSession.getMapper(MyObjectMapper.class).deleteMyObjectById(objectId);
	}

	@Override
	public void updateMyObject(MyObject myObject) {
		logger.info("Method invocation : updateMyObject");
		
		sqlSession.getMapper(MyObjectMapper.class).updateMyObject(myObject);
	}

}
